from django.db import models


# Create your models here.
class UserInfo(models.Model):
    name = models.CharField(max_length=32, verbose_name='用户名')
    password = models.CharField(max_length=32, verbose_name='密码')
    position = models.CharField(max_length=32, verbose_name='职位')


class Category(models.Model):
    bigcategory = models.ForeignKey(to='Bigcategory', verbose_name='大分类标题', default=1, related_name='categories',
                                    on_delete=models.CASCADE)
    subcategory = models.OneToOneField(to='Subcategory', verbose_name='子分类标题', null=True, unique=True,
                                       related_name='categories', on_delete=models.CASCADE)

    class Meta:
        unique_together = (('bigcategory', 'subcategory'),)


class Bigcategory(models.Model):
    title = models.CharField(max_length=32, verbose_name='大分类标题')


class Subcategory(models.Model):
    title = models.CharField(max_length=32, verbose_name='子分类标题')


class Article(models.Model):
    title = models.CharField(max_length=32, verbose_name='文章标题')
    author = models.ForeignKey(to='UserInfo', verbose_name='作者', on_delete=models.DO_NOTHING)
    abstract = models.TextField(max_length=128, verbose_name='文章摘要')
    publish_time = models.DateTimeField(auto_now_add=True, verbose_name='发布时间')
    category = models.ForeignKey(to='Category', default=1, verbose_name='分类', on_delete=models.DO_NOTHING)
    content = models.OneToOneField(to='ArticleDetail', on_delete=models.CASCADE, verbose_name='文章详情',
                                   related_name='article')
    count_read = models.IntegerField(default=0)


class ArticleDetail(models.Model):
    content = models.TextField(verbose_name='文章内容')


class Comment(models.Model):
    commentator = models.ForeignKey(to='UserInfo', verbose_name='评论者', on_delete=models.DO_NOTHING)
    article = models.ForeignKey(to='Article', verbose_name='评论的文章', on_delete=models.DO_NOTHING,
                                related_name='comments')
    content = models.TextField(verbose_name='评论内容', max_length=200)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='评论时间')


class Pic(models.Model):
    path = models.CharField(max_length=256)
